package com.equis.architecture.service {
	
	import com.equis.architecture.controls.WindowLock;
	
	import mx.rpc.events.FaultEvent;
	import mx.rpc.remoting.mxml.RemoteObject;
	
	public class BlockingService extends Service {
		
		private var inCall:Boolean = false; 
		
		public function BlockingService(item:RemoteObject) {
			super(item);
		}
		
		public override function invoke(name:String, ... parameters):* {
			if(this.inCall) {
				return;
			}
			this.inCall = true;
			WindowLock.INSTANCE.lock();
			super.doInvoke(name, parameters);
		}
		
		protected override function invokeResultCallback(result:*):void {
			this.cleanUpCall();
			super.invokeResultCallback(result);
		}

		public override function handleFault(event:FaultEvent):void {
			this.cleanUpCall();
			super.handleFault(event);
		}
		
		private function cleanUpCall():void {
			this.inCall = false;
			WindowLock.INSTANCE.unLock();
	    }
		
	}
	
}